<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Db;

/**
 * 示例接口
 */
class Hospital extends Api
{

    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['gethospital'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    /**
     * 获取城市的医院
     */

    public function gethospital(){


        $city=$this->request->param('city');
        $key=$this->request->param('key');

        if (!$city){
            $city='成都市';
        }

        $city=mb_substr($city,0,2);

        $city=Db::name('city')->where('name','like','%'.$city.'%')->find();

        $where['status']=['eq',1];

        $where['city_id']=['eq',$city['id']];

        if ($key){
            $where['name']=['like','%'.$key.'%'];
        }



        $data=Db::name('hospital')->where($where)->order('id desc')->select();

        foreach ($data as $k=>$v){
            $data[$k]['image']=cdnurl($v['image'],true);
        }

        $this->success('获取城市的医院',$data);


    }


    /**
     * 医院详情
     */
    public function gethospitalbyid(){

        $id=$this->request->param('id');

        $data=Db::name('hospital')->where(['id'=>$id])->find();

        if (!$data){
            $this->error('医院不存在');
        }

        $data['image']=cdnurl($data['image'],true);

        $this->success('医院详情',$data);

    }


    /**
     * 服务信息
     */
    public function gethospitalserver(){

        $id=$this->request->param('id');


        $data=Db::name('hospital_service')
            ->alias('s')
            ->join('service h','s.sid=h.id')
            ->where('s.status','eq','1')
            ->where('s.hid','eq',$id)
            ->field('s.*,h.image as aimage')
            ->select();


        foreach ($data as $k=>$v){
            $data[$k]['image']=cdnurl($v['aimage'],true);
        }

        $this->success('服务信息',$data);



    }

    /**
     * 服务详情
     */
    public function getserverbyid()
    {
        $id=$this->request->param('id');

        $data=Db::name('hospital_service')
            ->where(['status'=>1])
            ->where(['id'=>$id])
            ->find();

        if (!$data){
            $this->error('服务不存在');
        }
        $data['image']=cdnurl($data['image'],true);

        $this->success('服务详情',$data);

    }

    public function getserverbyidb()
    {
        $id=$this->request->param('id');

        $data=Db::name('hospital_service')
            ->where(['status'=>1])
            ->where(['id'=>$id])
            ->find();

        if (!$data){
            $this->error('服务不存在');
        }
        $data['image']=cdnurl($data['image'],true);

        $this->success('服务详情',$data);

    }

    /**
     * 城市相关陪诊员 fa_worker  points
     */
    public function getcityworker()
    {

        $city=$this->request->param('citys');

        $selectedDate=$this->request->param('selectedDate');

        $date=date('m-d',strtotime($selectedDate));

        $city=mb_substr($city,0,2);

        $worker=Db::name('worker')->alias('w')
            ->join('worker_bang b','w.user_id=b.uid')
            ->where('w.citys','like','%'.$city.'%')
            ->where(['b.date'=>$date])
            ->where(['w.status'=>'1'])
            ->where(['b.status'=>1])
            ->field('w.id,w.name,w.avatar,w.aimage,w.mobile,w.sex,b.addt,b.endt,w.year,w.hsp')
            ->select();

//echo Db::getLastSql();

        foreach ($worker as $k=>$v){

            $worker[$k]['avatar']=cdnurl($v['avatar'],true);
            $worker[$k]['aimage']=cdnurl($v['aimage'],true);

        }

        $this->success('城市相关陪诊员',$worker);


    }


















}